package com.example.wacoffee_manage.Mapper;

import com.example.wacoffee_manage.annotation.AutoFill;
import com.example.wacoffee_manage.common.OperationType;
import com.example.wacoffee_manage.pojo.coupon;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface couponMapper {

    @Select("select id,name,min_amount,start_time,end_time,`value`,description,stock,status from coupon")
    List<coupon> getAll();

    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    @Insert("insert into coupon(name,min_amount,start_time,end_time,`value`,description,creator,create_time,updater,update_time,stock,status) values(#{name},#{minAmount},#{startTime},#{endTime},#{value},#{description},#{creator},#{createTime},#{updater},#{updateTime},#{stock},#{status})")
    void add(coupon coupon);

    @Delete("delete from coupon where id=#{id}")
    void delete(Integer id);

    @AutoFill(OperationType.UPDATE)
    @Update("update coupon set name=#{name},min_amount=#{minAmount},start_time=#{startTime},end_time=#{endTime},`value`=#{value},description=#{description},stock=#{stock} where id=#{id}")
    void update(coupon coupon);

    @Update("update coupon set status=#{status} where id= #{id}")
    void updateStatus(Integer id, Integer status);

    @Select("select id,name,min_amount,start_time,end_time,`value`,description,stock,status from coupon where id= #{id}")
    coupon getById(Integer id);
}
